﻿using MediatR;
using Microsoft.EntityFrameworkCore;
using ProductIntory.Domains;
using ProductIntory.ErrorCodes;
using ProductIntory.Infrastructures.Interface;
using ProductIntory.Read.Apis.Application.Command.ProductionStorageCommands;

namespace ProductIntory.Read.Apis.Application.CommandHandler.ProductionStorageCommandHandlers
{
    public class UpdateProductionStorageCommandHandlers : IRequestHandler<UpdateProductionStorageCommand, ApiResult<int>>
    {
        IBaseRepository<ProductionStorage> ProductionStorage;

        public UpdateProductionStorageCommandHandlers(IBaseRepository<ProductionStorage> ProductionStorage)
        {
            this.ProductionStorage = ProductionStorage;
        }

        public async Task<ApiResult<int>> Handle(UpdateProductionStorageCommand request, CancellationToken cancellationToken)
        {
            var list = await ProductionStorage.GetAll().FirstOrDefaultAsync(c => c.Productionstorage_ID == request.ProductionStorage.Productionstorage_ID);
            await ProductionStorage.Update(request.ProductionStorage);

            return new ApiResult<int>
            {
                Code = ApiEnum.success,
                Message = "Product Inspection updated successfully",
                Data = 1
            };
        }
    }
}
